<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.2"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>GrPPI: Map pattern</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.svg"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">GrPPI
   &#160;<span id="projectnumber">1.0</span>
   </div>
   <div id="projectbrief">Generic and Reusable Parallel Pattern Interface</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.2 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div><!-- top -->
<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title">Map pattern </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The <b>map</b> pattern applies an operation to every element in one or multiple data sets, generating a new data set as an output.</p>
<p>The interface to the <b>map</b> pattern is provided by function <code><a class="el" href="group__map__pattern.html#gaf326a6fa32cef31ddb3379cfc042edfe" title="Invoke Map pattern on a data sequence.">grppi::map()</a></code>. As all functions in <em>GrPPI</em>, this function takes as its first argument an execution policy.</p>
<div class="fragment"><div class="line"><a class="code" href="group__map__pattern.html#gaf326a6fa32cef31ddb3379cfc042edfe">grppi::map</a>(exec, other_arguments...);</div>
<div class="ttc" id="agroup__map__pattern_html_gaf326a6fa32cef31ddb3379cfc042edfe"><div class="ttname"><a href="group__map__pattern.html#gaf326a6fa32cef31ddb3379cfc042edfe">grppi::map</a></div><div class="ttdeci">void map(const Execution &amp;ex, std::tuple&lt; InputIterators... &gt; firsts, InputIt last, OutputIt first_out, Transformer transform_op)</div><div class="ttdoc">Invoke Map pattern on a data sequence.</div><div class="ttdef"><b>Definition:</b> map.h:51</div></div>
</div><!-- fragment --><h1><a class="anchor" id="autotoc_md653"></a>
Map variants</h1>
<p>There are several variants:</p>
<ul>
<li><em>Unary map</em>: A map taking a single input sequence.</li>
<li><em>N-ary map</em>: A map taking multiple input sequences.</li>
</ul>
<h1><a class="anchor" id="autotoc_md654"></a>
Key elements in a map</h1>
<p>The key element in a <b>map</b> pattern is the <b>Transformer</b> operation.</p>
<p>The transformer may be a <b>UnaryTransformer</b> or a <b>MultiTransformer</b>.</p>
<p>A <b>UnaryTransformer</b> is any C++ callable entity that takes a data item and transforms it. The input type and the output type may differ. Thus, a unary transformer <code>op</code> is any operation that, given an input <code>x</code> of type <code>T</code> and output type <code>U</code>, makes valid the following:</p>
<div class="fragment"><div class="line">U res = op(x);</div>
</div><!-- fragment --><p>A <b>MultiTransformer</b> is any C++ callable entity that takes data items, one of each input sequence, and transforms them into an output value. The input types and the output type may differ. Thus, a multi-transformer <code>op</code> is any operation that, given inputs <code>x1, x2, ... , xN</code> of types <code>T1, T2, ... , TN</code> and an output type <code>U</code>, makes valid the following:</p>
<div class="fragment"><div class="line">U res = op(x1,x2,...,xN)</div>
</div><!-- fragment --><h1><a class="anchor" id="autotoc_md655"></a>
Details on map variants</h1>
<h2><a class="anchor" id="autotoc_md656"></a>
Unary map</h2>
<p>An unary <b>map</b> takes a data set and transforms each element in the data set by applying an unary function and generating a new data set.</p>
<p>The only interface currently offered for this pattern is based in iterators (following the C++ standard library conventions):</p>
<ul>
<li>The input data set is specified by two iterators.</li>
<li>The output data set is specified by an iterator to the start of the output sequence.</li>
</ul>
<hr  />
<p> <b>Example</b>: Doubling values in a vector. </p><div class="fragment"><div class="line">vector&lt;double&gt; v = get_the_vector();</div>
<div class="line">vector&lt;double&gt; w(v.size());</div>
<div class="line"><a class="code" href="group__map__pattern.html#gaf326a6fa32cef31ddb3379cfc042edfe">map</a>(exec, begin(v), end(v), begin(w),</div>
<div class="line">    [](<span class="keywordtype">double</span> x) { <span class="keywordflow">return</span> 2 *x; }</div>
<div class="line">);</div>
</div><!-- fragment --> <hr  />
<h2><a class="anchor" id="autotoc_md659"></a>
N-ary map</h2>
<p>A n-ary <b>map</b> takes multiple data sets and transforms a tuple of elements from those data sets by applying a n-ary function and generating a new data set.</p>
<p>The only interface currently offered for this pattern is based in iterators:</p>
<ul>
<li>The first data set is specified by two iterators.</li>
<li>The output data set is specified by an iterator to the start of the output sequence.</li>
<li>All the other input data sets are specified by iterators to the start of the input data sequences.</li>
</ul>
<hr  />
<p> <b>Example</b>: Computing the addition of three vectors. </p><div class="fragment"><div class="line">vector&lt;double&gt; v1 = get_first_vector();</div>
<div class="line">vector&lt;double&gt; v2 = get_second_vector();</div>
<div class="line">vector&lt;double&gt; v3 = get_third_vector();</div>
<div class="line">vector&lt;double&gt; w(v1.size());</div>
<div class="line"><a class="code" href="group__map__pattern.html#gaf326a6fa32cef31ddb3379cfc042edfe">map</a>(exec, begin(v1), end(v1), begin(w),</div>
<div class="line">  [](<span class="keywordtype">double</span> x, <span class="keywordtype">double</span> y, <span class="keywordtype">double</span> z) { <span class="keywordflow">return</span> x+y+z; },</div>
<div class="line">  begin(v2), begin(v3)</div>
<div class="line">);</div>
</div><!-- fragment --> <hr  />
 </div></div><!-- contents -->
</div><!-- PageDoc -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.2
</small></address>
</body>
</html>
